#pragma once
#include <d3dx9.h>
#include "TwEngineHead.h"

class TwTerrainMgr;
class TwCamera;
class TwFontDraw;
class TwTextureMgr;

#define  SCREEN_WIDTH  800
#define  SCREEN_HEIGHT 700

struct FVERTEX2D
{
	float x, y, z, rhw;
	DWORD color;
	float u, v;
	FVERTEX2D()
		:z(0)
		,rhw(1.f)
		,color(0xFFFFFFFF)
	{}
};
const DWORD FVERTEX2D_STRIDE = sizeof(FVERTEX2D);
const DWORD FVERTEX2D_FVF = (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1);

#ifndef FINDEX
typedef WORD FINDEX;
const FINDEX FINDEX_Default2D[6] = {0, 1, 2, 2, 1, 3};
#endif

#define MAX_SURFACE 200


class TwEngineDx
{
public:
	TwEngineDx(void);
	~TwEngineDx(void);

	void				SetDevice(void * pkDevice){ m_pDevice = (LPDIRECT3DDEVICE9)pkDevice;};
	LPDIRECT3DDEVICE9	GetDevice(){ return m_pDevice;}

	bool				BeginRender();
	void				Render2D();
	void				Render3D();
	void				Render();
	void				EndRender();
	void				InitMgr();

	void				InitTerrainMgr();
	void				InitFontMgr();



	TwTextureMgr*		GetTextureMgr(){ return m_pkTextureMgr;};

	void				RenderTerrain();

	void				UpdateCamera(float fElapsedTime);
	void				MsgHandle( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );

	void				Release();
	void				Destroy();

	float		        GetFps();
	const TwCamera*		GetCamera()const {return m_pkCameraTest;}

	void				ApplyCameraDevice(void* pkDevice);
private:
	LPDIRECT3DDEVICE9	m_pDevice;
	TwTextureMgr*		m_pkTextureMgr;
	TwTerrainMgr*		m_pkTerrainTest;
	TwCamera*			m_pkCameraTest;
	TwFontDraw*			m_pkFontMgr;
};

extern TwEngineDx* g_Render;